using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Media;
using Styx;
using Styx.Helpers;
using Styx.Common;
using Styx.Common.Helpers;
using Styx.CommonBot.POI;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

namespace NuckChorris
{
    public partial class Classname : CombatRoutine
    {
        public override sealed string Name { get { return "Windwalker Monk CC by Pasterke"; } }

        public override WoWClass Class { get { return WoWClass.Monk; } }

        private static LocalPlayer Me { get { return StyxWoW.Me; } }

        private void slog(string format, params object[] args) //use for slogging
        {
            Logging.Write(Colors.Yellow, format, args);
        }

        public override bool WantButton { get { return true; } }

        public override void OnButtonPress()
        {
            NuckChorris.Form1 myConfig = new NuckChorris.Form1();
            myConfig.ShowDialog();
        }
        public override void Initialize()
        {
            Updater.CheckForUpdate();
            Lua.Events.AttachEvent("MODIFIER_STATE_CHANGED", HandleModifierStateChanged);
        }

        public bool RemoveDeadTargets = true;

        public static Stopwatch fightTimer = new Stopwatch();

        private readonly static WaitTimer RollTimer = new WaitTimer(TimeSpan.FromMilliseconds(1500));

        public override void Pulse()
        {
            try
            {

                if (Me.CurrentTarget != null
                    && (!Me.Combat
                    || !Me.IsAutoAttacking)
                    && fightTimer.IsRunning
                    && fightTimer.Elapsed.Seconds >= 30)
                {
                    Blacklist.Add(Me.CurrentTarget, BlacklistFlags.All, new TimeSpan(0, 3, 0));
                    fightTimer.Reset();
                    LogMsg("Take too much time to attack, blacklisting current target", 1);
                    return;
                }
                if (Me.Combat && Me.CurrentTarget.IsFriendly)
                {
                    Me.ClearTarget();
                    LogMsg("Friendly Target removed because I'm in Combat (" + Me.CurrentTarget.Name + ")", 1);
                    return;
                }
                if (!Me.CurrentTarget.IsPlayer && Me.CurrentTarget.IsFriendly)
                {
                    return;
                }
                if (Me.Combat && RemoveDeadTargets && Me.CurrentTarget.IsDead)
                {
                    Me.ClearTarget();
                    LogMsg("Dead Target removed (" + Me.CurrentTarget.Name + ")", 1);
                    return;
                }
                if (!Me.CurrentTarget.Lootable
                    && Me.CurrentTarget.IsDead
                    && RemoveDeadTargets
                    && Me.CurrentTarget.Distance >= 5)
                {
                    Me.ClearTarget();
                    LogMsg("Looted Target removed (" + Me.CurrentTarget.Name + ")", 1);
                    return;
                }

            }
            catch { }
        }


        #region CC_Begin


        public override bool NeedRest
        {
            get
            {
                if (MeIsAlive
                    && !Me.IsGhost
                    && !Me.IsSwimming
                    && !Me.Mounted
                    && !Me.IsFlying
                    && !Me.OnTaxi)
                {
                    if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.DrinkEat)
                    {
                        return true;
                    }
                }
                return false;
            }
        }

        public override void Rest()
        {
            if (MeIsAlive
                && !Me.IsGhost
                && !Me.IsSwimming
                && !Me.Mounted
                && !Me.IsFlying
                && !Me.OnTaxi)
            {
                if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.DrinkEat)
                {
                    if (!Me.HasAura("First Aid"))
                    {
                        Styx.CommonBot.Rest.Feed();
                    }
                }
            }
        }

        #endregion

        #region Pull

        public override void Pull()
        {
            if (UseSpells)
            {
                if (!NuckChorrisSettings.myPrefs.DisableAllMovement)
                {
                    if (Me.CurrentTarget.IsDead
                        || !Me.CurrentTarget.Attackable
                        || (Me.Combat && Me.CurrentTarget.IsFriendly))
                    {
                        Me.ClearTarget();
                    }

                    if (!NuckChorrisSettings.myPrefs.DisableTargetting)
                    {
                        EnsureTarget();
                    }
                    if (Me.CurrentTarget != null
                        && Me.CurrentTarget.IsAlive
                        && SpellManager.HasSpell(Provoke)
                        && GetSpellCooldown(Provoke).TotalSeconds <= 0
                        && !Me.IsChanneling)
                    {
                        if (SpellManager.CanCast(Provoke))
                        {
                            MoveInRange(38f);
                            Me.CurrentTarget.Face();
                            if (Me.IsMoving)
                            {
                                WoWMovement.MoveStop();
                            }

                            SpellManager.Cast(Provoke);
                            fightTimer.Restart();
                            LogMsg("Pulling with Provoke", 6);
                            LastSpell = "Provoke";

                            if (Me.CurrentTarget != null
                                && Me.CurrentTarget.IsAlive
                                && Me.CurrentTarget.IsWithinMeleeRange)
                            {
                                Lua.DoString("StartAttack()");
                            }
                        }
                    }
                    else if (Me.CurrentTarget != null
                        && Me.CurrentTarget.IsAlive
                        && SpellManager.HasSpell(CracklingJadeLighting)
                        && GetSpellCooldown(CracklingJadeLighting).TotalSeconds <= 0
                        && !Me.IsChanneling
                        && LastSpell != Provoke)
                    {
                        if (SpellManager.CanCast(CracklingJadeLighting))
                        {
                            MoveInRange(38f);
                            Me.CurrentTarget.Face();
                            if (Me.IsMoving)
                            {
                                WoWMovement.MoveStop();
                            }

                            SpellManager.Cast(CracklingJadeLighting);
                            fightTimer.Restart();
                            LogMsg("Pulling with " + CracklingJadeLighting, 6);
                            LastSpell = CracklingJadeLighting;

                            if (Me.CurrentTarget != null
                                && Me.CurrentTarget.IsAlive
                                && Me.CurrentTarget.IsWithinMeleeRange)
                            {
                                Lua.DoString("StartAttack()");
                            }
                        }
                    }
                    else if (Me.CurrentTarget != null
                        && Me.CurrentTarget.IsAlive
                        && SpellManager.HasSpell(Jab)
                        && GetSpellCooldown(Jab).TotalSeconds <= 0
                        && Me.EnergyPercent >= 40
                        && LastSpell != Provoke
                        && LastSpell != CracklingJadeLighting
                        && !Me.IsChanneling)
                    {
                        if (SpellManager.CanCast(Jab))
                        {
                            MoveInRange(MeleeRange);
                            Me.CurrentTarget.Face();
                            if (Me.IsMoving)
                            {
                                WoWMovement.MoveStop();
                            }

                            SpellManager.Cast(Jab);
                            fightTimer.Restart();
                            LogMsg("Pulling with Jab", 6);
                            LastSpell = "Jab";

                            Lua.DoString("StartAttack()");
                        }
                    }
                }
            }

        }


        #endregion

        #region Pull Buffs

        public override bool NeedPullBuffs { get { return false; } }

        public override void PullBuff() { }

        #endregion

        #region Pre Combat Buffs

        public override bool NeedPreCombatBuffs
        {
            get
            {
                if (MeIsAlive)
                {
                    if (SpellManager.HasSpell(LegacyEmperor)
                        && NuckChorrisSettings.myPrefs.agibuff
                        && !Me.HasAura(LegacyEmperor)
                        && !Me.HasAura("Blessing of Kings")
                        && !Me.HasAura("Mark of the Wild")
                        && LastSpell != LegacyEmperor)
                    {
                        CastBuff(LegacyEmperor, 2);
                    }
                    if (SpellManager.HasSpell(LehacyOfTheWhiteTiger)
                        && NuckChorrisSettings.myPrefs.critbuff
                        && !Me.HasAura(LehacyOfTheWhiteTiger)
                        && !Me.HasAura("Dalaran Brilliance")
                        && LastSpell != LehacyOfTheWhiteTiger)
                    {
                        CastBuff(LehacyOfTheWhiteTiger, 2);
                    }
                }
                return false;
            }
        }

        public override void PreCombatBuff()
        {

        }

        #endregion

        #region Combat Buffs

        public override bool NeedCombatBuffs
        {
            get
            {
                if (MeIsAlive)
                {

                }
                return false;
            }
        }

        public override void CombatBuff()
        {

        }

        #endregion

        #region Heal

        public override bool NeedHeal
        {
            get
            {
                return false;
            }
        }

        public override void Heal()
        {

        }

        #endregion

        #region Falling

        public void HandleFalling() { }

        #endregion

        #region Combat

        public override void Combat()
        {
            if (Paused)
            {
                return;
            }
            if (!NuckChorrisSettings.myPrefs.DisableTargetting)
            {
                EnsureTarget();
            }
            // protection (orange log msg)
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.ExpelHarm
                && GetSpellCooldown(ExpelHarm).TotalSeconds == 0
                && LastSpell != ExpelHarm)
            {
                LogMsg(ExpelHarm, 0);
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.FortBrew
                && GetSpellCooldown(FortBrew).TotalSeconds == 0
                && LastSpell != FortBrew)
            {
                LogMsg(FortBrew, 0);
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.UseTouchOfKarma
                && GetSpellCooldown(TouchOfkarma).TotalSeconds == 0
                && LastSpell != TouchOfkarma)
            {
                LogMsg(TouchOfkarma, 0);
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.HealingSpheresPercent
                && NuckChorrisSettings.myPrefs.HealingSpheres == 1)
            {
                UseHealingSpheres();
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.healthstone
                && NuckChorrisSettings.myPrefs.HHealthstone == 1)
            {
                HealthStone();
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.LifeSpirit
                && NuckChorrisSettings.myPrefs.HLifeSpirit == 1)
            {
                LifeSpirit();
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.HealthPotion
                && NuckChorrisSettings.myPrefs.HHealthPotions == 1)
            {
                Drinken();
            }
            if (Me.HealthPercent <= NuckChorrisSettings.myPrefs.GiftOfNaruu
                && NuckChorrisSettings.myPrefs.HNaruu == 1)
            {
                CastBuff("Gift of the Naaru", 2);
            }
            if (SpellManager.HasSpell(LegacyEmperor)
                        && NuckChorrisSettings.myPrefs.agibuff
                        && !Me.HasAura(LegacyEmperor)
                        && !Me.HasAura("Blessing of Kings")
                        && !Me.HasAura("Mark of the Wild")
                        && LastSpell != LegacyEmperor)
            {
                CastBuff(LegacyEmperor, 2);
            }
            if (SpellManager.HasSpell(LehacyOfTheWhiteTiger)
                && NuckChorrisSettings.myPrefs.critbuff
                && !Me.HasAura(LehacyOfTheWhiteTiger)
                && !Me.HasAura("Dalaran Brilliance")
                && LastSpell != LehacyOfTheWhiteTiger)
            {
                CastBuff(LehacyOfTheWhiteTiger, 2);
            }
            if (Me.GroupInfo.IsInRaid
                && !Me.HasAura("Flask of Spring Blossoms")
                && NuckChorrisSettings.myPrefs.AgiFlask)
            {
                AgiFlask();
            }
            if (Me.CurrentTarget != null
                && Me.GroupInfo.IsInRaid
                && NuckChorrisSettings.myPrefs.VirmenPotion
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                VirmenPotion();
            }
            if (CanUseTrinket1)
            {
                UseTrinket1();
            }
            if (CanUseTrinket2)
            {
                Usetrinket2();
            }
            if (CanUseEngiGloves)
            {
                UseEngiGloves();
            }
            MoveInRange(MeleeRange);

            Facing();


            if (UnfriendlyUnits.Count() >= NuckChorrisSettings.myPrefs.UseAoe
                  && Me.Level >= 46)
            {
                AoeRotation();
            }

            MainRotation();


        }

        #endregion


        #region Spells


        private void AutoAttack()
        {
            if (!Me.IsAutoAttacking)
            {
                Lua.DoString("StartAttack()");
            }

        }
        #endregion Spells


        #region MainRotation

        public void MainRotation()
        {
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Jab)
                && (Me.CurrentChi < 2
                || Me.Level < 3)
                && Me.CurrentEnergy >= 40)
            {
                if (SpellManager.CanCast(Jab))
                {
                    SpellManager.Cast(Jab);
                    LogMsg(Jab, 1);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(ChiBrew)
                && !spellOnCooldown(ChiBrew)
                && Me.CurrentChi < 3)
            {
                if (SpellManager.CanCast(ChiBrew))
                {
                    SpellManager.Cast(ChiBrew);
                    LogMsg(ChiBrew, 2);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(TigerEyeBrew)
                && buffExists(TigerEyeBrew, Me)
                && Me.GetAuraByName(TigerEyeBrew).StackCount >= NuckChorrisSettings.myPrefs.TEBStacks
                && (Me.CurrentTarget.HealthPercent >= NuckChorrisSettings.myPrefs.NoTigereyeBrew
                || IsBoss()))
            {
                if (SpellManager.CanCast(TigerEyeBrew))
                {
                    SpellManager.Cast(TigerEyeBrew);
                    LogMsg(TigerEyeBrew, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(RisingSunKick)
                && !spellOnCooldown(RisingSunKick)
                && Me.CurrentChi >= 2)
            {
                if (SpellManager.CanCast(RisingSunKick))
                {
                    SpellManager.Cast(RisingSunKick);
                    LogMsg(RisingSunKick, 3);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(TouchDead)
                && ((NuckChorrisSettings.myPrefs.GTouchDeath == 1 && buffExists(DeathNote, Me))
                || (Me.CurrentChi >= 3 && buffExists(DeathNote, Me)))
                && ((Me.CurrentTarget.HealthPercent >= NuckChorrisSettings.myPrefs.NoTouchOfDeath && !IsBoss())
                || IsBoss())
                && Me.CurrentTarget.IsWithinMeleeRange)
            {

                if (SpellManager.CanCast(TouchDead))
                {
                    SpellManager.Cast(TouchDead);
                    LogMsg(TouchDead, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Jab)
                && (Me.CurrentChi < 2
                || Me.Level < 3)
                && Me.CurrentEnergy >= 40)
            {
                if (SpellManager.CanCast(Jab))
                {
                    SpellManager.Cast(Jab);
                    LogMsg(Jab, 1);
                }

            }
            // Combo breaker procs (red log msg)
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(BlackoutKick)
                && buffExists(CBBlackoutKick, Me))
            {
                if (SpellManager.CanCast(BlackoutKick))
                {
                    SpellManager.Cast(BlackoutKick);
                    LogMsg(BlackoutKick, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(TigerPalm)
                && buffExists(CBTigerPalm, Me))
            {
                if (SpellManager.CanCast(TigerPalm))
                {
                    SpellManager.Cast(TigerPalm);
                    LogMsg(TigerPalm, 4);
                }

            }
            // end combo breakers

            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(TigerPalm)
                && (!buffExists(TigerPower, Me)
                || buffTimeLeft(TigerPower, Me) < 5000)
                && Me.CurrentChi >= 1
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(TigerPalm))
                {
                    SpellManager.Cast(TigerPalm);
                    LogMsg(TigerPalm, 3);
                }

            }
            // interrupt (red log msg)
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(SpearHandStrike)
                && Me.CurrentTarget.IsCasting
                && Me.CanInterruptCurrentSpellCast
                && !spellOnCooldown(SpearHandStrike)
                && Me.CurrentTarget.IsTargetingMeOrPet
                && LastSpell != SpearHandStrike)
            {
                if (SpellManager.CanCast(SpearHandStrike))
                {
                    SpellManager.Cast(SpearHandStrike);
                    LogMsg(SpearHandStrike, 4);
                }

            }
            //player specific
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(LegSweep)
                && Me.CurrentTarget.IsPlayer
                && !spellOnCooldown(LegSweep)
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(LegSweep))
                {
                    SpellManager.Cast(LegSweep);
                    LogMsg(LegSweep, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(GrappleWeapon)
                && Me.CurrentTarget.IsPlayer
                && !spellOnCooldown(GrappleWeapon)
                && spellCooldownLeft(LegSweep).TotalSeconds > 5
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(GrappleWeapon))
                {
                    SpellManager.Cast(GrappleWeapon);
                    LogMsg(GrappleWeapon, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(DiffuseMagic)
                && Me.CurrentTarget.IsPlayer
                && !spellOnCooldown(DiffuseMagic)
                && spellCooldownLeft(GrappleWeapon).TotalSeconds > 8)
            {
                if (SpellManager.CanCast(DiffuseMagic))
                {
                    SpellManager.Cast(DiffuseMagic);
                    LogMsg(DiffuseMagic, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(DiffuseMagic)
                && Me.CurrentTarget.IsCasting
                && !spellOnCooldown(DiffuseMagic))
            {
                if (SpellManager.CanCast(DiffuseMagic))
                {
                    SpellManager.Cast(DiffuseMagic);
                    LogMsg(DiffuseMagic, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Disable)
                && Me.CurrentTarget.IsPlayer
                && !spellOnCooldown(Disable)
                && !debuffExists(Disable, Me.CurrentTarget))
            {
                if (SpellManager.CanCast(Disable))
                {
                    SpellManager.Cast(Disable);
                    LogMsg(Disable, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Xuen)
                && !spellOnCooldown(Xuen)
                && IsBoss())
            {
                if (SpellManager.CanCast(Xuen))
                {
                    SpellManager.Cast(Xuen);
                    LogMsg(Xuen, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Xuen)
                && !NuckChorrisSettings.myPrefs.Xuen
                && !spellOnCooldown(Xuen)
                && !IsBoss())
            {
                if (SpellManager.CanCast(Xuen))
                {
                    SpellManager.Cast(Xuen);
                    LogMsg(Xuen, 4);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(FistofFury)
                && !spellOnCooldown(FistofFury)
                && Me.CurrentChi >= 3
                && Me.CurrentEnergy < 70
                && !Me.HasAura("Time Warp")
                && !Me.HasAura("Bloodlust")
                && !Me.HasAura("Heroism")
                && !Me.IsMoving)
            {
                if (SpellManager.CanCast(FistofFury))
                {
                    SpellManager.Cast(FistofFury);
                    LogMsg(FistofFury, 3);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(BlackoutKick)
                && Me.CurrentChi >= 2
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(BlackoutKick))
                {
                    SpellManager.Cast(BlackoutKick);
                    LogMsg(BlackoutKick, 3);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(EnergizingBrew)
                && Me.CurrentEnergy < 25
                && !spellOnCooldown(EnergizingBrew)
                && LastSpell != EnergizingBrew)
            {
                if (SpellManager.CanCast(EnergizingBrew))
                {
                    SpellManager.Cast(EnergizingBrew);
                    LogMsg(EnergizingBrew, 1);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Jab)
                && Me.CurrentEnergy >= 40
                && Me.CurrentChi < 2
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(Jab))
                {
                    SpellManager.Cast(Jab);
                    LogMsg(Jab, 3);
                }

            }
            return;
        }
        #endregion MainRotation

        #region AoeRotation

        // crimson log msg colors
        public void AoeRotation()
        {
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(Jab)
                && Me.CurrentEnergy >= 40
                && Me.CurrentChi < 2
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(Jab))
                {
                    SpellManager.Cast(Jab);
                    LogMsg(Jab, 3);
                }
            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(TigerPalm)
                && (!buffExists(TigerPower, Me)
                || debuffTimeLeft(TigerPower, Me) < 5000)
                && Me.CurrentChi >= 1)
            {
                if (SpellManager.CanCast(TigerPalm))
                {
                    SpellManager.Cast(TigerPalm);
                    LogMsg(TigerPalm, 3);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(EnergizingBrew)
                && Me.EnergyPercent <= 40
                && !spellOnCooldown(EnergizingBrew))
            {
                if (SpellManager.CanCast(EnergizingBrew))
                {
                    SpellManager.Cast(EnergizingBrew);
                    LogMsg(EnergizingBrew, 5);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(TouchOfkarma)
                && Me.CurrentChi >= 2
                && GetSpellCooldown(TouchOfkarma).TotalSeconds == 0
                && Me.HealthPercent <= NuckChorrisSettings.myPrefs.UseTouchOfKarma)
            {
                if (SpellManager.CanCast(TouchOfkarma))
                {
                    SpellManager.Cast(TouchOfkarma);
                    LogMsg(TouchOfkarma, 5);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(ChiBurst)
                && Me.CurrentChi >= 2)
            {
                if (SpellManager.CanCast(ChiBurst))
                {
                    SpellManager.Cast(ChiBurst);
                    LogMsg(ChiBurst, 5);
                }

            }

            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(SpinningCraneKick)
                && Me.EnergyPercent >= 40
                && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (SpellManager.CanCast(SpinningCraneKick))
                {
                    SpellManager.Cast(SpinningCraneKick);
                    LogMsg(SpinningCraneKick, 5);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(RisingSunKick)
                && !spellOnCooldown(RisingSunKick)
                && Me.CurrentChi >= 2)
            {
                if (SpellManager.CanCast(RisingSunKick))
                {
                    SpellManager.Cast(RisingSunKick);
                    LogMsg(RisingSunKick, 5);
                }

            }
            if (Me.CurrentTarget != null
                && SpellManager.HasSpell(ChiWave)
                && Me.CurrentChi >= 2)
            {
                if (SpellManager.CanCast(ChiWave))
                {
                    SpellManager.Cast(ChiWave);
                    LogMsg(ChiWave, 5);
                }

            }
            return;

        }
        #endregion AoeRotation

        IEnumerable<WoWUnit> UnfriendlyUnits
        {
            get { return ObjectManager.GetObjectsOfType<WoWUnit>(true, false).Where(u => !u.IsDead && u.CanSelect && u.Attackable && !u.IsFriendly && u.IsWithinMeleeRange); }
        }

        public static TimeSpan GetSpellCooldown(string spell)
        {
            SpellFindResults results;
            if (SpellManager.FindSpell(spell, out results))
            {
                if (results.Override != null)
                    return results.Override.CooldownTimeLeft;
                return results.Original.CooldownTimeLeft;
            }


            return TimeSpan.MaxValue;
        }

        public static float MeleeRange
        {
            get
            {
                if (StyxWoW.Me.CurrentTargetGuid == 0)
                    return 0f;

                if (StyxWoW.Me.CurrentTarget.IsPlayer)
                    return 3.5f;

                return 3.5f;

                //return Math.Max(5f, StyxWoW.Me.CombatReach + 1.3333334f + StyxWoW.Me.CurrentTarget.CombatReach);
            }
        }

        #region Movement
        public void MoveInRange(float dist)
        {
            if (Me.CurrentTarget != null
                && !NuckChorrisSettings.myPrefs.DisableAllMovement)
            {
                float range = dist;
                while (StyxWoW.Me.Location.Distance(StyxWoW.Me.CurrentTarget.Location) > range)
                {
                    if (Me.CurrentTarget != null
                        && Me.CurrentTarget.Distance > 12
                        && SpellManager.CanCast(Roll)
                        && !Me.Combat
                        && !Me.Mounted)
                    {
                        SpellManager.Cast(Roll);
                    }
                    Navigator.MoveTo(StyxWoW.Me.CurrentTarget.Location);
                };

                Navigator.PlayerMover.MoveStop();
                return;
            }

        }
        #endregion Movement
        #region facing
        public void Facing()
        {
            if (Me.CurrentTarget != null
                && !NuckChorrisSettings.myPrefs.DisableFacing)
            {
                Me.CurrentTarget.Face();
            }
            return;
        }
        #endregion facing

        #region Kind of Target

        private bool IsBoss()
        {
            if (Me.CurrentTarget != null
                && Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.WorldBoss)
            {
                return true;
            }
            else if (Me.CurrentTarget != null
                && Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.Elite
                && Me.CurrentTarget.MaxHealth >= (65 * 1000000))
            {
                return true;
            }
            else if (Me.CurrentTarget != null
                && target.IsBoss(Me.CurrentTarget))
            {
                return true;
            }
            else if (Me.CurrentTarget != null
                && Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.Elite
                && Me.CurrentTarget.MaxHealth >= (Me.MaxHealth * NuckChorrisSettings.myPrefs.ElitesNotInParty)
                && !Me.GroupInfo.IsInParty
                && !Me.IsInInstance
                && !Me.GroupInfo.IsInRaid)
            {
                return true;
            }
            else if (Me.CurrentTarget != null
                && Me.CurrentTarget.Name.Contains("Training Dummy"))
            {
                return true;
            }

            else { return false; }
        }

        #endregion Kind of Target

    }
}
